<template>
  <el-container>
    <el-header>
      <div class="hmBox">
        <img src="../assets/img/heima.png" alt />
        <span>电商后台管理系统</span>
      </div>
      <div class="logOut">
        <el-row>
          <el-button type="info" @click=" logout() ">退出</el-button>
        </el-row>
      </div>
    </el-header>
    <el-container>
      <el-aside :width=" collqie? '65px':'200px'">
        <div class="togglrbBar" @click=" qie() ">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          unique-opened
          :collapse="collqie"
          :collapse-transition="false"
          router
        >
          <el-submenu
            :index="item.id+''"
            v-for="item in menuList"
            :key="item.id"
            :style="{width: collqie?'65px':'200px'}"
          >
            <template slot="title">
              <i :class="'iconfont icon-' + iconList[item.path]"></i>
              <span>{{item.authName}}</span>
            </template>

            <el-menu-item :index="item2.path" v-for="item2 in item.children" :key="item2.id">
              <i class="el-icon-menu"></i>
              {{item2.authName}}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data: () => {
    return {
      collqie: false,
      menuList: [],
      iconList: {
        users: 'users',
        rights: 'tijikongjian',
        goods: 'shangpin',
        orders: 'danju',
        reports: 'baobiao'
      }
    }
  },
  created () {
    this.getaisdeList()
  },
  methods: {
    qie () {
      this.collqie = !this.collqie
      // console.log(this.collqie)
    },
    logout () {
      this.$confirm('确定要退出系统', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 清空token
          window.sessionStorage.setItem('token', '')
          // 跳转到login页面
          this.$router.push('/login')
        })
        .catch(() => {})
    },
    async getaisdeList () {
      var { data: dt } = await this.$http.get('menus')
      // console.log(dt)
      if (dt.meta.status === 200) {
        this.menuList = dt.data
      } else {
        this.$message.errorr(dt.meta.msg)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;

  .el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 0;
    .hmBox {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #fff;
      font-size: 22px;
      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }
    }
  }
  .el-aside {
    background-color: #333744;
    .togglrbBar {
      height: 25px;
      width: 100%;
      background-color: #4a5064;
      text-align: center;
      line-height: 25px;
      font-size: 12px;
      color: #fff;
    }
    .el-menu {
      background-color: #333744;
      i {
        margin-right: 14px;
      }
      span {
        font-size: 13px;
      }
      .el-menu-item {
        font-size: 13px;
        i {
          margin-right: 9px;
        }
      }
    }
  }
  .el-main {
    background-color: #eaedf1;
  }
}
</style>
